{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 杨力骁 320200931431"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Question 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "\n",
    "data = pd.read_csv('gaze.csv')\n",
    "\n",
    "confidence = data[data['confidence'] >=0.9]\n",
    "confidence.to_csv(r'D:\\DataScience\\数据科学编程\\0.9confidence.csv')\n",
    "print(confidence.shape[0])  "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Question 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "norm_pos_x: 121084\n",
      "norm_pos_y: 120135\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "118852"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import numpy as np\n",
    "\n",
    "data = pd.read_csv('gaze.csv')\n",
    "\n",
    "def three_sigma(ser1):\n",
    "    mean_value = ser1.mean()\n",
    "    std_value = ser1.std() \n",
    "    rule = (mean_value - 3 * std_value < ser1) & (ser1.mean() + 3 * ser1.std() > ser1)\n",
    "    index = np.arange(ser1.shape[0])[rule]\n",
    "    inrange = ser1.iloc[index]  \n",
    "    return inrange\n",
    "\n",
    "x_num = three_sigma(data['norm_pos_x']).shape[0]\n",
    "print('norm_pos_x:',x_num)\n",
    "y_num = three_sigma(data['norm_pos_y']).shape[0]\n",
    "print('norm_pos_y:',y_num)\n",
    "result = x_num & y_num\n",
    "result"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Question 3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0           1970-01-02 00:29:10.776780+00:00\n",
       "1           1970-01-02 00:29:10.776787+00:00\n",
       "2           1970-01-02 00:29:10.779709+00:00\n",
       "3           1970-01-02 00:29:10.779759+00:00\n",
       "4           1970-01-02 00:29:10.787485+00:00\n",
       "                         ...                \n",
       "125259   1970-01-02 00:34:03.695600500+00:00\n",
       "125260   1970-01-02 00:34:03.697570500+00:00\n",
       "125261      1970-01-02 00:34:03.701580+00:00\n",
       "125262      1970-01-02 00:34:03.703608+00:00\n",
       "125263      1970-01-02 00:34:03.705574+00:00\n",
       "Name: gaze_timestamp, Length: 125264, dtype: datetime64[ns, UTC]"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import time\n",
    "\n",
    "data = pd.read_csv('gaze.csv')\n",
    "data2 = pd.to_datetime(data['gaze_timestamp'], unit='s', utc=True)\n",
    "data2"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Question 4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "427.6261076608589\n"
     ]
    }
   ],
   "source": [
    "length = len(data['gaze_timestamp'])\n",
    "data4 = data['gaze_timestamp']\n",
    "max_time = max(data4)\n",
    "min_time = min(data4)\n",
    "mean_time = (max_time - min_time)/length\n",
    "sampling_rate = 1/mean_time\n",
    "print(sampling_rate)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Question 5"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "                         world_index  confidence  norm_pos_x  norm_pos_y  \\\n",
      "gaze_timestamp                                                             \n",
      "1970-01-01 00:01:28.150   139.590619    0.710526    0.439230    0.477953   \n",
      "1970-01-01 00:01:28.160   427.327388    0.823882    0.315246    0.422748   \n",
      "1970-01-01 00:01:28.170   727.262406    0.818867    0.463320    0.387076   \n",
      "1970-01-01 00:01:28.180  1027.420300    0.891241    0.396745    0.424165   \n",
      "1970-01-01 00:01:28.190  1326.979118    0.785471    0.379900    0.380401   \n",
      "1970-01-01 00:01:28.200  1627.273259    0.814194    0.380568    0.427541   \n",
      "1970-01-01 00:01:28.210  1927.376724    0.913206    0.394634    0.432810   \n",
      "1970-01-01 00:01:28.220  2227.304185    0.924815    0.417549    0.417772   \n",
      "1970-01-01 00:01:28.230  2527.261632    0.861221    0.393230    0.450729   \n",
      "1970-01-01 00:01:28.240  2827.209210    0.905355    0.401741    0.446221   \n",
      "1970-01-01 00:01:28.250  3127.156899    0.883552    0.438003    0.422756   \n",
      "1970-01-01 00:01:28.260  3427.388525    0.837652    0.424930    0.435930   \n",
      "1970-01-01 00:01:28.270  3727.249825    0.922919    0.397060    0.438005   \n",
      "1970-01-01 00:01:28.280  4027.248363    0.924187    0.394686    0.424216   \n",
      "1970-01-01 00:01:28.290  4327.169705    0.862455    0.427455    0.453087   \n",
      "1970-01-01 00:01:28.300  4627.220873    0.944679    0.411236    0.430831   \n",
      "1970-01-01 00:01:28.310  4927.314106    0.911966    0.407537    0.458938   \n",
      "1970-01-01 00:01:28.320  5227.233590    0.885634    0.420252    0.434842   \n",
      "1970-01-01 00:01:28.330  5527.237973    0.904911    0.410326    0.477685   \n",
      "1970-01-01 00:01:28.340  5827.196449    0.906714    0.405692    0.475158   \n",
      "\n",
      "                         gaze_point_3d_x  gaze_point_3d_y  gaze_point_3d_z  \\\n",
      "gaze_timestamp                                                               \n",
      "1970-01-01 00:01:28.150      1057.200767      -452.357218     -7705.641117   \n",
      "1970-01-01 00:01:28.160      3337.368667     -1701.716549    -22726.698137   \n",
      "1970-01-01 00:01:28.170     -1242.344319       642.260330      8615.747968   \n",
      "1970-01-01 00:01:28.180     -2108.479843       906.247607     14102.763104   \n",
      "1970-01-01 00:01:28.190      -768.089154       360.364234      5323.206488   \n",
      "1970-01-01 00:01:28.200      -374.635967        67.621475      1697.460916   \n",
      "1970-01-01 00:01:28.210       -25.523896       -42.417587      -235.858448   \n",
      "1970-01-01 00:01:28.220       -50.595705         6.410614       172.322187   \n",
      "1970-01-01 00:01:28.230       -48.748418       241.475250        15.568423   \n",
      "1970-01-01 00:01:28.240       -89.063626        48.632932       820.914005   \n",
      "1970-01-01 00:01:28.250       -22.722898        18.080452       228.662741   \n",
      "1970-01-01 00:01:28.260      -567.859086       306.974687      4021.785692   \n",
      "1970-01-01 00:01:28.270      -162.368800        65.515843       965.130946   \n",
      "1970-01-01 00:01:28.280     -1142.464295       485.814929      6895.807307   \n",
      "1970-01-01 00:01:28.290      -872.740001       357.027980      5099.627736   \n",
      "1970-01-01 00:01:28.300      1879.454417      -992.978787    -14821.463638   \n",
      "1970-01-01 00:01:28.310         4.926919        15.475906       158.618249   \n",
      "1970-01-01 00:01:28.320       -96.477818        67.200756       710.727354   \n",
      "1970-01-01 00:01:28.330      -153.315682        64.262367      1066.041403   \n",
      "1970-01-01 00:01:28.340       -60.501627       -43.480292      -586.324610   \n",
      "\n",
      "                         eye_center0_3d_x  eye_center0_3d_y  eye_center0_3d_z  \\\n",
      "gaze_timestamp                                                                  \n",
      "1970-01-01 00:01:28.150         14.452774         14.927761        -20.027057   \n",
      "1970-01-01 00:01:28.160         18.376092         14.900405        -20.301762   \n",
      "1970-01-01 00:01:28.170         17.769681         14.903067        -20.325156   \n",
      "1970-01-01 00:01:28.180         19.211247         14.909636        -20.153195   \n",
      "1970-01-01 00:01:28.190         16.025616         14.690458        -20.652484   \n",
      "1970-01-01 00:01:28.200         17.905347         14.398223        -20.954195   \n",
      "1970-01-01 00:01:28.210         18.374399         14.384531        -20.933248   \n",
      "1970-01-01 00:01:28.220         19.053186         14.379750        -20.902658   \n",
      "1970-01-01 00:01:28.230         17.316647         14.433381        -20.905859   \n",
      "1970-01-01 00:01:28.240         18.474805         14.483989        -20.756235   \n",
      "1970-01-01 00:01:28.250         17.713527         14.500347        -20.779722   \n",
      "1970-01-01 00:01:28.260         16.873866         14.520387        -20.820135   \n",
      "1970-01-01 00:01:28.270         18.457917         14.504044        -20.787465   \n",
      "1970-01-01 00:01:28.280         18.617055         14.503239        -20.779560   \n",
      "1970-01-01 00:01:28.290         17.337049         14.509463        -20.842460   \n",
      "1970-01-01 00:01:28.300         19.205400         14.500250        -20.750294   \n",
      "1970-01-01 00:01:28.310         18.099087         14.505705        -20.804868   \n",
      "1970-01-01 00:01:28.320         17.605449         14.508140        -20.829220   \n",
      "1970-01-01 00:01:28.330         17.632638         14.508006        -20.827878   \n",
      "1970-01-01 00:01:28.340         17.436216         14.508988        -20.842538   \n",
      "\n",
      "                         gaze_normal0_x  gaze_normal0_y  gaze_normal0_z  \\\n",
      "gaze_timestamp                                                            \n",
      "1970-01-01 00:01:28.150       -0.127847        0.067605        0.889367   \n",
      "1970-01-01 00:01:28.160       -0.244505        0.090579        0.951078   \n",
      "1970-01-01 00:01:28.170       -0.022525        0.007327        0.966231   \n",
      "1970-01-01 00:01:28.180       -0.166638       -0.027207        0.973686   \n",
      "1970-01-01 00:01:28.190       -0.118421        0.126559        0.969294   \n",
      "1970-01-01 00:01:28.200       -0.157902        0.074265        0.957535   \n",
      "1970-01-01 00:01:28.210       -0.146237        0.051453        0.963780   \n",
      "1970-01-01 00:01:28.220       -0.084801        0.065100        0.975999   \n",
      "1970-01-01 00:01:28.230       -0.166249        0.057002        0.930546   \n",
      "1970-01-01 00:01:28.240       -0.144264        0.043767        0.950410   \n",
      "1970-01-01 00:01:28.250       -0.099678        0.045776        0.949888   \n",
      "1970-01-01 00:01:28.260       -0.145078        0.057476        0.925963   \n",
      "1970-01-01 00:01:28.270       -0.146731        0.050133        0.954728   \n",
      "1970-01-01 00:01:28.280       -0.150297        0.058772        0.955741   \n",
      "1970-01-01 00:01:28.290       -0.093084        0.052902        0.943567   \n",
      "1970-01-01 00:01:28.300       -0.128417        0.013018        0.980309   \n",
      "1970-01-01 00:01:28.310       -0.135633        0.043154        0.945174   \n",
      "1970-01-01 00:01:28.320       -0.134965        0.041200        0.949101   \n",
      "1970-01-01 00:01:28.330       -0.145121        0.033099        0.923413   \n",
      "1970-01-01 00:01:28.340       -0.147904       -0.011806        0.928220   \n",
      "\n",
      "                         eye_center1_3d_x  eye_center1_3d_y  eye_center1_3d_z  \\\n",
      "gaze_timestamp                                                                  \n",
      "1970-01-01 00:01:28.150        -39.709336         14.549297        -19.780972   \n",
      "1970-01-01 00:01:28.160        -35.448202         14.565285        -25.917069   \n",
      "1970-01-01 00:01:28.170        -35.357652         14.696238        -26.142450   \n",
      "1970-01-01 00:01:28.180        -37.086310         14.788350        -23.480002   \n",
      "1970-01-01 00:01:28.190        -36.983088         14.811906        -23.625989   \n",
      "1970-01-01 00:01:28.200        -36.891102         14.793806        -23.749654   \n",
      "1970-01-01 00:01:28.210        -37.100070         14.775316        -23.444882   \n",
      "1970-01-01 00:01:28.220        -37.135465         14.774882        -23.415255   \n",
      "1970-01-01 00:01:28.230        -37.274171         14.768857        -23.238987   \n",
      "1970-01-01 00:01:28.240        -37.760146         14.754257        -22.535525   \n",
      "1970-01-01 00:01:28.250        -37.704338         14.754874        -22.626959   \n",
      "1970-01-01 00:01:28.260        -37.279303         14.776168        -23.354749   \n",
      "1970-01-01 00:01:28.270        -37.168200         14.782509        -23.543019   \n",
      "1970-01-01 00:01:28.280        -37.168377         14.779644        -23.535104   \n",
      "1970-01-01 00:01:28.290        -37.168463         14.778240        -23.531224   \n",
      "1970-01-01 00:01:28.300        -37.168463         14.778240        -23.531224   \n",
      "1970-01-01 00:01:28.310        -37.168463         14.778240        -23.531224   \n",
      "1970-01-01 00:01:28.320        -37.168463         14.778240        -23.531224   \n",
      "1970-01-01 00:01:28.330        -37.168463         14.778240        -23.531224   \n",
      "1970-01-01 00:01:28.340        -37.081902         14.778114        -23.633386   \n",
      "\n",
      "                         gaze_normal1_x  gaze_normal1_y  gaze_normal1_z  \n",
      "gaze_timestamp                                                           \n",
      "1970-01-01 00:01:28.150       -0.148169        0.097099        0.982526  \n",
      "1970-01-01 00:01:28.160       -0.144661       -0.042391        0.978452  \n",
      "1970-01-01 00:01:28.170       -0.126900        0.244343        0.946971  \n",
      "1970-01-01 00:01:28.180       -0.052744        0.080061        0.991507  \n",
      "1970-01-01 00:01:28.190       -0.220017        0.090418        0.967101  \n",
      "1970-01-01 00:01:28.200       -0.151808        0.053767        0.984200  \n",
      "1970-01-01 00:01:28.210       -0.124904        0.055827        0.987059  \n",
      "1970-01-01 00:01:28.220       -0.157212        0.108161        0.975239  \n",
      "1970-01-01 00:01:28.230       -0.116777        0.027554        0.987826  \n",
      "1970-01-01 00:01:28.240       -0.110134        0.055378        0.986496  \n",
      "1970-01-01 00:01:28.250       -0.120907        0.106926        0.979176  \n",
      "1970-01-01 00:01:28.260       -0.107375        0.052359        0.990495  \n",
      "1970-01-01 00:01:28.270       -0.108207        0.048913        0.986929  \n",
      "1970-01-01 00:01:28.280       -0.118526        0.056326        0.988779  \n",
      "1970-01-01 00:01:28.290       -0.142864        0.105255        0.981360  \n",
      "1970-01-01 00:01:28.300       -0.090173        0.077162        0.990872  \n",
      "1970-01-01 00:01:28.310       -0.120012        0.060891        0.987876  \n",
      "1970-01-01 00:01:28.320       -0.112555        0.075101        0.990206  \n",
      "1970-01-01 00:01:28.330       -0.101355        0.053868        0.990909  \n",
      "1970-01-01 00:01:28.340       -0.056927        0.074000        0.990144  \n"
     ]
    }
   ],
   "source": [
    "data['gaze_timestamp'] = pd.to_datetime(data['gaze_timestamp'].values, unit='ms')\n",
    "data3 = data.resample('10ms', on='gaze_timestamp').mean()\n",
    "print(data3[0: 20])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
